package top.yuyufeng.mbuy.utils;

import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;

/**
 * @author yuyufeng
 */
public class MD5Util {
    private static String salt = "!@#mbuy^*&";

    public static String getMd5(String code) throws UnsupportedEncodingException {
        return DigestUtils.md5DigestAsHex(code.getBytes("utf-8"));
    }

    /**
     * 加密带盐值
     *
     * @param code
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String getMd5WithSalt(String code) {
        code += salt;
        try {
            return DigestUtils.md5DigestAsHex(code.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println(MD5Util.getMd5("yuyufeng19941224"));
        System.out.println(MD5Util.getMd5WithSalt("yuyufeng19941224"));
    }
}
